package cn.agiledata.bank.tel.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cn.agiledata.bank.tel.service.ITelCallManager;
import cn.agiledata.bank.tel.service.ITelCallService;
import cn.agiledata.bank.tel.bean.TelCallBean;
import com.vnv.infrastructure.action.IPBBaseAction;
import com.vnv.infrastructure.exception.IPBException;
import com.vnv.infrastructure.logic.IPBAppFactory;

public class TelCallAction extends IPBBaseAction {
	
	public int hasAccessPermission(int accessLevel, HttpServletRequest request) throws IPBException {
		return 1;
	}

	public ActionForward putTelCall(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws IPBException, Exception {

		TelCallBean telBean = new TelCallBean();

		String msg = request.getParameter("msg");
		String telNum = request.getParameter("telNum");
		String user = request.getParameter("user");
		// String reNum=request.getParameter("reNum");

		telBean.setTelMsg(msg);
		telBean.setTelNum(telNum);
		telBean.setAccoutName(user);
		// telBean.setAccountID();
		this.getTelService().putTelData(telBean);

		return mapping.findForward("callSuccess");
	}

	public ActionForward reTelCall(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws IPBException, Exception {
		String user = request.getParameter("user");
		String reNum = request.getParameter("reNum");
		return null;
	}

	public ActionForward getTelData(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws IPBException, Exception {

//		TelCallBean telBean = new TelCallBean();
//		if (!this.getTelService().empty())
//			telBean = (TelCallBean) this.getTelService().getTelData();
//
//		String msg = telBean.getTelMsg();
//		String telNum = telBean.getTelNum();
//		String accoutName = telBean.getAccoutName();
//		String accountID = telBean.getAccountID();
//		response.setContentType("txt;charset=GB2312");
//
//		if (msg != null && telNum != null) {
//			PrintWriter out = response.getWriter();
//			out.print(accountID);
//			out.print(":");
//			out.print(accoutName);
//			out.print(":");
//			out.print(telNum);
//			out.print(":");
//			out.print(msg);
//			out.close();
//		}
//		return null;
		String data = "";

			ITelCallManager telCallMgr =(ITelCallManager)IPBAppFactory.getObj("TelCallManager");
			data = telCallMgr.getTelData();

		response.setContentType("txt;charset=GB2312");
		if (data != "") {
			PrintWriter out = response.getWriter();
			out.print(data);
			out.close();
		}
		return null;
	}

	public ITelCallService getTelService() throws IPBException {
		return (ITelCallService) IPBAppFactory.getObj(ITelCallService.MGR_ID);
	}
}
